package com.fyzk.activity.down_numhistory;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.bean.model.SsqLiShiJX;
import com.tyjc.lottery.R;
import com.fyzk.utils.AppUtil;

import java.util.List;

public class NumHistoryAdapter extends BaseAdapter {

    private List<SsqLiShiJX> liShi;
    private Context context;
    private boolean isPL3;

    public NumHistoryAdapter(List<SsqLiShiJX> bellow_lishi, Context context, boolean isPL3) {
        liShi = bellow_lishi;
        this.context = context;
        this.isPL3 = isPL3;
    }

    @Override
    public int getCount() {
        if (liShi == null) {
            return 0;
        }
        return liShi.size();
    }

    @Override
    public Object getItem(int position) {

        return null;
    }

    @Override
    public long getItemId(int position) {

        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        SsqLiShiJX ssqLiShiJX = liShi.get(position);
        View view = null;
        Log.e("fjl", isPL3 + "");
        if (!isPL3) {
            view = LayoutInflater.from(context).inflate(R.layout.ssq_bellow_listview_layout, null);
            LinearLayout b_ll_list = (LinearLayout) view.findViewById(R.id.ssq_b_ll_list);
            b_ll_list.getLayoutParams().height = AppUtil.getHeight() * 25 / 560;
            TextView qiTextView = (TextView) view.findViewById(R.id.ssq_b_tv_qi);
            TextView hongTextView = (TextView) view.findViewById(R.id.ssq_b_tv_hong);
            TextView lanTextView = (TextView) view.findViewById(R.id.ssq_b_tv_lan);

            qiTextView.setText(ssqLiShiJX.getQi());
            hongTextView.setText(ssqLiShiJX.getHongQiu());
            lanTextView.setText(ssqLiShiJX.getLanQiu());
        } else {
            view = LayoutInflater.from(context).inflate(R.layout.ssq_bellow_listview_layout_pl3, null);
            if (position % 2 == 0) {
                view.setBackgroundColor(Color.parseColor("#f4f4f4"));
            } else {
                view.setBackgroundColor(Color.WHITE);
            }
            LinearLayout b_ll_list = (LinearLayout) view.findViewById(R.id.ssq_b_ll_list);
            b_ll_list.getLayoutParams().height = AppUtil.getHeight() * 25 / 560;
            TextView qiTextView = (TextView) view.findViewById(R.id.ssq_b_tv_qi);
            TextView hongTextView = (TextView) view.findViewById(R.id.ssq_b_tv_hong);
            TextView lanTextView = (TextView) view.findViewById(R.id.ssq_b_tv_leixing);

            qiTextView.setText(ssqLiShiJX.getQi().replace("期", ""));
            hongTextView.setText(ssqLiShiJX.getHongQiu());
            //三个数字 一样 就是豹子  两个一样 是组三 其他组6
            if (isBaozi(ssqLiShiJX.getHongQiu())) {
                lanTextView.setText("豹子");
            } else if (isZuSan(ssqLiShiJX.getHongQiu())) {
                lanTextView.setText("组三");
            } else {
                lanTextView.setText("组六");
            }
        }
        return view;
    }

    private boolean isBaozi(String hong) {
        String[] strs = hong.split(" ");
        if (strs == null || strs.length != 3) {
            return false;
        }
        return (strs[0].equals(strs[1]) && strs[0].equals(strs[2]));
    }

    private boolean isZuSan(String hong) {
        String[] strs = hong.split(" ");
        if (strs == null || strs.length != 3) {
            return false;
        }
        return (strs[0].equals(strs[1]) || strs[0].equals(strs[2]) || strs[1].equals(strs[2]));
    }

    public void setList(List<SsqLiShiJX> liShi) {
        this.liShi = liShi;
        notifyDataSetChanged();
    }
}
